package com.hotel.meals.controller;


import com.hotel.common.param.Cart;
import com.hotel.common.param.GetFood;
import com.hotel.meals.model.req.CartReq;
import com.hotel.meals.service.CartItemService;
import com.hotel.user.entity.CartItem;
import com.hotel.user.entity.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author KK
 * @since 2024-06-19
 */
@RestController
@RequestMapping("/api")
public class CartItemController {
    @Autowired
    private CartItemService cartItemService;

    @PostMapping("/add")
    public String addToCart(@RequestBody List<CartItem> cartItems) {
        for (CartItem item : cartItems) {
            cartItemService.save(item);
        }
        return "Added to cart successfully";
    }

    @PostMapping("/checkoutResult")
    public ResponseDTO<List<CartItem>> checkout(@RequestBody Cart cart, HttpServletRequest request) {
        return cartItemService.checkout(cart,request);
    }
}

